package com.ruoyi.wxarea.controller;



import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wxarea.mapper.AreaMapper;
import com.ruoyi.wxarea.pojo.Area;
import com.ruoyi.wxarea.service.IAreaService;
import com.ruoyi.wxcommon.common.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * <p>
 * 地区 前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2024-05-06
 */
@RestController
@RequestMapping("/area")
public class AreaController extends BaseController {
    @Autowired
    IAreaService areaService;
    @Resource
    AreaMapper areaMapper;
    @GetMapping("/getAreaInfo")
    public List<Area> areaList(){
        return areaMapper.areaList();
    }
    @PostMapping("/get")
    public Result getArea(Integer pageIndex, Integer pageSize, String name){
        return areaService.getAreaName(pageIndex,pageSize,name);
    }

    @GetMapping("/userAreaInfo")
    public Result userAreaInfo(Integer id){
        return areaService.userAreaInfo(id);
    }

    /**
     * 查询校园地区管理列表
     */
    @RequiresPermissions("campusassistant:wxarea:list")
    @GetMapping("/list")
    public TableDataInfo list(Area area)
    {
        startPage();
        List<Area> list = areaService.selectAreaList(area);
        return getDataTable(list);
    }

    /**
     * 导出校园地区管理列表
     */
    @RequiresPermissions("campusassistant:wxarea:export")
    @Log(title = "校园地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Area area)
    {
        List<Area> list = areaService.selectAreaList(area);
        ExcelUtil<Area> util = new ExcelUtil<Area>(Area.class);
        util.exportExcel(response, list, "校园地区管理数据");
    }

    /**
     * 获取校园地区管理详细信息
     */
    @RequiresPermissions("campusassistant:wxarea:query")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(areaService.selectAreaByPkId(pkId));
    }

    /**
     * 新增校园地区管理
     */
    @RequiresPermissions("campusassistant:wxarea:add")
    @Log(title = "校园地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Area area)
    {
        return toAjax(areaService.insertArea(area));
    }

    /**
     * 修改校园地区管理
     */
    @RequiresPermissions("campusassistant:wxarea:edit")
    @Log(title = "校园地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Area area)
    {
        return toAjax(areaService.updateArea(area));
    }

    /**
     * 删除校园地区管理
     */
    @RequiresPermissions("campusassistant:wxarea:remove")
    @Log(title = "校园地区管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(areaService.deleteAreaByPkIds(pkIds));
    }

}

